package com.cqc.nestedrecyclerview01;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

/**
 * Created by ${cqc} on 2017/6/5.
 */

public class MyAdapter2 extends RecyclerView.Adapter {

    private List<StudentBean> studentList;

    public MyAdapter2(List<StudentBean> studentList) {
        this.studentList = studentList;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_2, parent, false);
        MyViewHolder holder = new MyViewHolder(itemView);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
        MyViewHolder holder = (MyViewHolder) viewHolder;
        StudentBean info = studentList.get(position);
        holder.tv2.setText(info.getName());
        holder.tv3.setText(info.getAge());
    }

    @Override
    public int getItemCount() {
        return studentList.size();
    }


    static class MyViewHolder extends RecyclerView.ViewHolder {

        TextView tv2;
        TextView tv3;

        public MyViewHolder(View itemView) {
            super(itemView);
            tv2 = (TextView) itemView.findViewById(R.id.tv2);
            tv3 = (TextView) itemView.findViewById(R.id.tv3);
        }
    }
}
